package com.android.monee.data.access.json;

import com.android.monee.data.access.BudgetDao;
import com.android.monee.data.access.inMemory.DaoUtils;
import com.android.monee.data.model.Budget;
import com.android.monee.view.activity.MoneeCtx;

public class BudgetDaoJson extends AbstractObservableDaoJson<Budget, Integer> implements BudgetDao{

	private static BudgetDaoJson instance;
	
	public static BudgetDaoJson getInstance(){
		if(instance == null){
			instance = new BudgetDaoJson();
			instance.init(MoneeCtx.rootDir, Budget.class, Integer.class);
		}
		
		return instance;
	}
	
	//TODO : delete budget => delete mens sinon les mens sont affectées au prochain budget créé
	
	@Override
	public void insert(Budget obj) {
		Budget budget = new Budget(obj);
		super.insert(budget);
		obj.setId(budget.getId());
	}

	@Override
	public void update(Budget obj) {
		Budget budget = new Budget(obj);
		super.update(budget);
	}

	@Override
	protected Integer getNextId() {
		return DaoUtils.getNextId(this.datas.values());
	}
}
